<?php

namespace app\commands;

use yii\console\Controller;
use app\services\SspService;
use app\services\CreativeService;
use app\controllers\BaseController;
use app\services\TanxService;
use app\services\AccuenService;
use app\traits\ModelTrait;

class SyncController extends Controller
{
    use ModelTrait;

    /**
     * syncronize adspace info from ssp to dsp
     */
    public function actionAdspace() {
        $adNets = $this->getAll('AdNetwork');
        foreach ($adNets as $adNet) {
            $adNet['id'] == 1 && $this->actionVamakerAdspace();
            $adNet['id'] == 2 && $this->actionAccuenAdspace();
        }
    }

    public function actionVamakerAdspace() {
        $service = new SspService('vamaker');
        $service->syncAdspace('bannerAdspace');
        $service->syncAdspace('videoAdspace');
        $service->syncAdspace('mobileAdspace');
        $service->syncAdspace('mobileVideoAdspace');
    }

    /**
     * upload creative from dsp to ssp
     */
    public function actionUpload() {
        $service = new CreativeService();
        $service->uploadCreative();
    }

    /**
     * update creative from dsp to ssp
     */
    public function actionUpdate() {
        $service = new CreativeService();
        $service->updateCreative();
    }

    /**
     * update creative audit status from ssp to dsp
     */
    public function actionUpdateAuditStatus() {
        $service = new CreativeService();
        $service->updateCreativeAuditStatus();
    }

    /**
     * Sync and Tanx Creative
     */
    public function actionAddTanxCreative() {
        $serv = new TanxService();
        $serv->addTanxCreative();
    }

    public function actionGetTanxCreative() {
        $serv = new TanxService();
        $serv->getTanxCreative();
    }

    public function actionGetAllTanxCreatives() {
        $serv = new TanxService();
        $serv->getAllTanxCreatives();
    }

    /**
     * Sync Accuen Adspaces
     */
    public function actionAccuenAdspace() {
        $service = new AccuenService('Acelink');
        $service->syncAdspace('bannerAdspace');
        $service->syncAdspace('videoAdspace');
        $service->syncAdspace('mobileAdspace');
        $service->syncAdspace('mobileVideoAdspace');
    }

    public function actionMediaList() {
        $adNets = $this->getAll('AdNetwork'); 
        foreach ($adNets as $adNet) {
            $adNet['id'] == 1 && $this->actionVamakerMediaList();
            $adNet['id'] == 2 && $this->actionAccuenMediaList();
        }
    }

    public function actionVamakerMediaList() {
        $service = new SspService('vamaker');
        $service->syncMediaList();
    }

    public function actionAccuenMediaList() {
        $service = new AccuenService('Acelink');
        $service->syncMediaList();
    }
}//end

